package nodes;

import compiler.Compiler;
import compiler.SymbolTable;

import descriptors.AbstractDescr;
import descriptors.TypeDescr;

public class TypeNode extends AbstractNode {

	IdentNode ident;
	AbstractNode type;
	
	public TypeNode(IdentNode ident,AbstractNode type,int line,int column){
		super(line,column);
		this.ident=ident;
		this.type=type;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public AbstractDescr compile(
			SymbolTable symbolTable, Compiler compiler) {
		AbstractDescr typeDescr=null;
		if(type instanceof IdentNode) {
			if(symbolTable.levelContains(compiler.level(),((IdentNode) type).ident()))
				typeDescr=symbolTable.get(compiler.level(),((IdentNode) type).ident());
			else // is that even a valid option?
				typeDescr=new TypeDescr(1,compiler.level(),ident.ident());
		}
		else typeDescr=type.compile(symbolTable,compiler);
		symbolTable.set(ident.ident(),typeDescr);
		return null;
	}

	@Override
	public void print() {
		trace("TypeNode");
		ident.print();
		type.print();
		unindent();
	}

}
